<template>
  <el-dialog title="结算确认" width="50%" :visible.sync="visible">
    <el-form ref="form" :model="form" class="dialog-form" label-position="right" label-width="120px">
      <el-form-item label="支付类型">
        <supplier-bank v-model="form.params.bankId" :supplier-id="self.form.supplierId" @change="bankChange" />
      </el-form-item>
      <div v-if="form.params.bank">
        <el-form-item v-if="form.params.bank.openingBank" label="开户行">
          <label>{{ form.params.bank.openingBank }}</label>
        </el-form-item>
        <el-form-item label="姓名">
          <label>{{ form.params.bank.accountName }}</label>
        </el-form-item>
        <el-form-item label="卡号">
          <label>{{ form.params.bank.cardNumber }}</label>
        </el-form-item>
      </div>
      <el-form-item label="核算金额">
        <label>￥<span class="money">{{ form.params.paymentAmount.toFixed(2) }}</span></label>
        <el-tag v-if="flag>2" size="mini" effect="plain" type="danger">{{ $constants.supOrderFlag.get(flag).label }}</el-tag>
      </el-form-item>
      <!-- <el-form-item label="实付金额" prop="params.paymentAmount" :rules="self.page.rules.num">
        <el-input-number v-model="form.params.paymentAmount" controls-position="right" :precision="2" :min="1" />
      </el-form-item> -->
      <el-form-item label="付款凭证" prop="params.certificate" :rules="self.page.rules.def">
        <form-upload-image v-model="form.params.certificate" size="mini" :remote="self.upload.img" />
      </el-form-item>
      <el-form-item label="补充描述" prop="message">
        <el-input v-model="form.message" type="textarea" :rows="2" placeholder="请输入补充描述" />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button size="mini" @click="visible = false">取 消</el-button>
      <el-button size="mini" type="primary" @click="submit">提交</el-button>
    </div>
  </el-dialog>
</template>
<script>
import SupplierBank from '@/components/SupplierBank'

export default {
  name: 'PurPaying',
  components: {
    SupplierBank
  },
  props: {
    value: {
      type: String,
      default: ''
    },
    self: {
      type: Object,
      default: () => { return {} }
    }
  },
  data() {
    return {
      visible: false,
      form: {
        id: null,
        message: null,
        params: {
          certificate: '',
          bank: null,
          actualAmount: null,
          paymentAmount: null,
          bankId: null
        }
      },
      flag: 0
    }
  },
  created() {

  },
  methods: {
    show(actualAmount, bankId, flag) {
      this.visible = true
      this.form.params.actualAmount = actualAmount
      this.form.params.paymentAmount = actualAmount
      this.form.params.bankId = bankId
      this.flag = flag
    },
    bankChange(current) {
      this.form.params.bank = current
    },
    submit() {
      const that = this
      that.form.id = that.value
      that.$refs['form'].validate((valid) => {
        if (!valid) {
          return
        }
        const loading = that.$loading()
        const url = that.self.page.router.remoteUrl + '/paying'
        that.self.service.post(url, that.form).then(res => {
          loading.close()
          if (res.code !== 200) {
            that.$message.error(res.message)
            return
          }
          that.$message.success('操作成功!')
          that.self.reload(true)
        }).catch((e) => {
          loading.close()
        })
      })
    }
  }
}
</script>
